package workbook;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.*;
import javax.swing.event.ListDataListener;

public class SwingTest2 extends JFrame{
		JLabel jl1=new JLabel("用  户 名:");
		JTextField jt1=new JTextField();
		JLabel jl2=new JLabel("密       码:");
		JPasswordField jt2=new JPasswordField();
		JLabel jl3=new JLabel("确认密码:");
		JPasswordField jt3=new JPasswordField();
		JLabel jl4=new JLabel("性      别:");
		JLabel jl5=new JLabel("爱      好:");
		JTextField jt5=new JTextField();
		JLabel jl6=new JLabel("地      址:");
		JTextArea jt6=new JTextArea();//多行文本
		JLabel jl7=new JLabel("学      历:");
		JButton jb1=new JButton("确认");
		JButton jb2=new JButton("取消");
		JComboBox box=new JComboBox(new Put());
		Container con=getContentPane();
		
		
		
		//box.setEditable(true);
		class Put extends AbstractListModel<String>implements ComboBoxModel<String>{
			String sele=null;
			String a[]=new String[]{"小学","中学","大专","本科","硕士","博士","教授"};
			public String getElementAt(int index) {
				return a[index];
			}

			public int getSize() {
				return a.length;
			}

			@Override
			public Object getSelectedItem() {
				// TODO Auto-generated method stub
				return sele;
			}

			@Override
			public void setSelectedItem(Object arg0) {
				sele=(String )arg0;
			}
			
		}
		
		
		public SwingTest2(){
			setVisible(true);
			setBounds(500,300,400,600);
			con.setBackground(Color.cyan);
			setLayout(null);
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			
			con.add(jl1);
			jl1.setBounds(10,10,100,20);
			con.add(jt1);
			jt1.setBounds(100,10,100,20);
			
			con.add(jl2);
			jl2.setBounds(10,40,100,20);
			con.add(jt2);
			jt2.setBounds(100,40,100,20);
			
			con.add(jl3);
			jl3.setBounds(10,70,100,20);
			con.add(jt3);
			jt3.setBounds(100,70,100,20);
			
			con.add(jl4);//性别
			jl4.setBounds(10,100,50,20);
			JRadioButton jr1=new JRadioButton("男");
			JRadioButton jr2=new JRadioButton("女");
			ButtonGroup bu=new ButtonGroup();
			bu.add(jr1);
			bu.add(jr2);
			con.add(jr1);
			con.add(jr2);
			jr1.setBounds(100,100,50,20);
			jr2.setBounds(160,100,50,20);
			
			con.add(jl5);//爱好
			jl5.setBounds(10,130,50,20);
			JCheckBox jc1=new JCheckBox("阅读");
			JCheckBox jc2=new JCheckBox("上网");
			JCheckBox jc3=new JCheckBox("游泳");
			JCheckBox jc4=new JCheckBox("旅游");
			con.add(jc1);
			jc1.setBounds(100,130,60,20);
			con.add(jc2);
			jc2.setBounds(165,130,60,20);
			con.add(jc3);
			jc3.setBounds(230,130,60,20);
			con.add(jc4);
			jc4.setBounds(295,130,60,20);

			
			con.add(jl6);//地址
			jl6.setBounds(10,160,50,20);
			con.add(jt6);
			jt6.setBounds(100,160,250,60);
			
			con.add(jl7);
			jl7.setBounds(10,230,50,20);
			
			
			
			
			con.add(box);
			box.setBounds(100,230,60,20);
			
			
			con.add(jb1);
			jb1.setBounds(100, 330, 60, 30);
			con.add(jb2);
			jb2.setBounds(180, 330, 60, 30);
			
			jb1.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent arg0) {
					String user=jt1.getText();//获取用户名
					String password1 =new String(jt2.getPassword());//获取密码
					String password2=new String(jt3.getPassword());//获取确认密码
					if(!password1.equals(password2)) {
						JDialog jd=new JDialog();
						jd.setTitle("警告");
						JLabel jb=new JLabel("您两次输入的密码不一致,请重新输入");
						jd.setVisible(true);
						jd.setBounds(500, 400, 333, 111);
						jd.add(jb);
						jb.setBounds(333,333,333,333);
					}
					
					ArrayList<String> list1=new ArrayList();
					jr1.addActionListener(new ActionListener() {
						
						public void actionPerformed(ActionEvent e) {
							String a="男";
							list1.add(a);
						}
					});
					jr2.addActionListener(new ActionListener() {
						
						public void actionPerformed(ActionEvent e) {
							String a="女";
							list1.add(a);
						}
					});
					//String sex=list1.get(list1.size()-1);//获取性别
					
					
						StringBuilder bu=new StringBuilder();//获取爱好
						jc1.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
							bu.append("阅读");
							}
						});
						jc2.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								bu.append("上网");
							}
						});
						jc3.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								bu.append("游泳");
							}
						});
						jc4.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								bu.append("旅游");
							}
						});
						String nuber=jt6.getText();//获取地址
						System.out.println(nuber);
						System.out.println(box.getSelectedItem());//获取学历
					}
			});
		}
		
		
		public static void main(String[] args) {
		SwingTest2 test2=	new SwingTest2();
		
		}
		

}

